package com.example.yiwei.crm.view.activity.coordinationActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.entity.BZFLEntity;
import com.example.yiwei.crm.entity.ManyiduEntity;
import com.example.yiwei.crm.json.coordinationjson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.List;

public class CoorDetileManYiDuActivity extends AppCompatActivity {
    private TextView txt_manager,txt_name,txt_age,txt_sex,txt_phone,txt_ly_time,txt_ys,txt_qk,txt_yy,txt_jd,txt_time,txt_yb;
    private TextView edit_mxb,edit_yy;
    private TextView sp_ly_l,sp_ly_r,sp_jz_l,sp_jz_r,sp_pj,sp_bz;
    private Button button1,button2;
    private TimePickerView mpv;
    private TimePickerView mpv1;
    private List<BZFLEntity> list3;
    private Date date1,date2;
    private int bz_id,pj_id;
    private String bz_s;
    private SharedPreferences sp;
    private List<String> list_pj;
    private String lysj,sj,ssp_ly_l,ssp_yl_r,ssp_jz_l,ssp_jzy;
    private List<String> list,bz_list;
    private ManyiduEntity manyiduEntity;
    private List<ManyiduEntity> mlist;
    private ArrayAdapter adapter1,adapter2,adapter3,adapter4,adapter5,adapter6;
    private ImageView im_back,im_comment;
    String result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coor_detile_man_yi_du);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        txt_manager = (TextView) findViewById(R.id.myd_add_manger_tv);
        im_back = (ImageView) findViewById(R.id.myd_add_img_back);
        txt_name = (TextView) findViewById(R.id.myd_add_name);
        txt_age = (TextView) findViewById(R.id.myd_add_age);
        txt_sex = (TextView) findViewById(R.id.myd_add_sex);
        txt_phone = (TextView) findViewById(R.id.myd_add_phone);
        txt_ly_time = (TextView) findViewById(R.id.myd_add_ly_time);
        txt_ys = (TextView) findViewById(R.id.myd_add_ys_tv);
        txt_qk = (TextView) findViewById(R.id.myd_add_jzqk_tv);
        txt_yy = (TextView) findViewById(R.id.myd_add_jzyy_tv);
        txt_jd = (TextView) findViewById(R.id.myd_add_jdr_tv);
        txt_time = (TextView) findViewById(R.id.myd_add_time);
        edit_yy = (TextView) findViewById(R.id.myd_add_yy_edit);
        txt_yb = (TextView) findViewById(R.id.myd_add_yb_number);
        edit_mxb = (TextView) findViewById(R.id.myd_add_mxb);
        sp_ly_l = (TextView) findViewById(R.id.myd_ly_l_sp);
        sp_ly_r = (TextView) findViewById(R.id.myd_ly_r_sp);
        sp_jz_r = (TextView) findViewById(R.id.myd_jz_r_sp);
        sp_jz_l = (TextView) findViewById(R.id.myd_jz_l_sp);
        sp_pj = (TextView) findViewById(R.id.myd_add_pj_sp);
        sp_bz = (TextView) findViewById(R.id.myd_add_bz);
        im_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        new Thread(new Runnable() {
            @Override
            public void run() {
                JSONObject object = new JSONObject();
                try {
                    object.put("KYA01",getIntent().getIntExtra("KYA01",0));
                    object.put("DEL01",0);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String json = object.toString();
                manyiduEntity = coordinationjson.jsonmanyiduMessage(baseClass.find_one_myd_msg_URL,json);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        initData();
                    }
                });
            }
        }).start();
    }

    private void initData() {
        txt_manager.setText(manyiduEntity.getManager_name());
        txt_name.setText(manyiduEntity.getName());
        txt_age.setText(manyiduEntity.getAge()+"");
        txt_sex.setText(manyiduEntity.getGender());
        txt_phone.setText(manyiduEntity.getPhone());
        txt_yb.setText(manyiduEntity.getYb());
        txt_ys.setText(manyiduEntity.getDoctor_name());
        txt_qk.setText(manyiduEntity.getState());
        txt_yy.setText(manyiduEntity.getHospital());
        txt_jd.setText(sp.getString("CID03",null));
        edit_mxb.setText(manyiduEntity.getMxb());
        edit_yy.setText(manyiduEntity.getResult());
        txt_time.setText(manyiduEntity.getDate());
        txt_ly_time.setText(manyiduEntity.getHospital_time());
        if (manyiduEntity.getLy_left()!=null&&!manyiduEntity.getLy_left().equals("")){
            if (manyiduEntity.getLy_left().equals(manyiduEntity.getAly_left())){
                sp_ly_l.setText(manyiduEntity.getLy_left());
            }else{
                sp_ly_l.setText(manyiduEntity.getLy_left()+"("+manyiduEntity.getAly_left()+")");
            }
        }
       if (manyiduEntity.getLy_right()!=null&&!manyiduEntity.getLy_right().equals("")){
           if (manyiduEntity.getLy_right().equals(manyiduEntity.getAly_right())){
               sp_ly_r.setText(manyiduEntity.getLy_right());
           }else{
               sp_ly_r.setText(manyiduEntity.getLy_right()+"("+manyiduEntity.getAly_right()+")");
           }
       }
       if (manyiduEntity.getJz_left()!=null&&!manyiduEntity.getJz_left().equals("")){
           if (manyiduEntity.getJz_left().equals(manyiduEntity.getAjz_left())){
               sp_jz_l.setText(manyiduEntity.getJz_left());
           }else {
               sp_jz_l.setText(manyiduEntity.getJz_left()+"("+manyiduEntity.getAjz_left()+")");
           }
       }
        if (manyiduEntity.getJz_right()!=null&&!manyiduEntity.getJz_right().equals("")){
            if (manyiduEntity.getJz_right().equals(manyiduEntity.getAjz_right())){
                sp_jz_r.setText(manyiduEntity.getJz_right());
            }else {
                sp_jz_r.setText(manyiduEntity.getJz_right()+"("+manyiduEntity.getAjz_right()+")");
            }
        }

        sp_bz.setText(manyiduEntity.getBZ());
        if(manyiduEntity.getManyidu()==1){
            sp_pj.setText("非常满意");
        }
        if(manyiduEntity.getManyidu()==2){
            sp_pj.setText("满意");
        }
        if(manyiduEntity.getManyidu()==3){
            sp_pj.setText("一般");
        }
        if(manyiduEntity.getManyidu()==4){
            sp_pj.setText("不满意");
        }

    }
}
